<template>
  <div class="student-info">
    <el-descriptions
        title="我的信息"
        direction="vertical"
        :column="4"
        size="large"
        border
    >
      <el-descriptions-item label="姓名">{{this.form.sName}}</el-descriptions-item>
      <el-descriptions-item label="性别">{{this.form.sSex}}</el-descriptions-item>
      <el-descriptions-item label="电话" :span="2">{{this.form.sTel}}</el-descriptions-item>
      <el-descriptions-item label="学习阶段">
        <el-tag size="small">{{this.form.sAccept}}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="本阶段学习天数">
        {{this.form.sDay}}
      </el-descriptions-item>
      <el-descriptions-item label="本阶段考试次数":span="2">
        {{this.form.sTestnum}}
      </el-descriptions-item>
      <el-descriptions-item label="科一成绩" >
        {{this.form1.gGrade1}}
      </el-descriptions-item>
      <el-descriptions-item label="科二成绩" >
        {{this.form1.gGrade2}}
      </el-descriptions-item>
      <el-descriptions-item label="科三成绩" >
        {{this.form1.gGrade3}}
      </el-descriptions-item>
      <el-descriptions-item label="科四成绩" >
        {{this.form1.gGrade4}}
      </el-descriptions-item>
      <el-descriptions-item label="报名状态" :span="2">

      </el-descriptions-item>
      <el-descriptions-item label="报名参加下次考试" :span="1">
        <el-button @click="enroll" type="primary">报名</el-button>
      </el-descriptions-item>
      <el-descriptions-item label="退出系统" :span="1">
        <el-button @click="goOut" type="danger">退出登录</el-button>
      </el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script>
import request from "@/util/request";
import {ref} from "vue";
import {ElMessage} from "element-plus";

export default {
  name: 'MyMessage',
  data(){
    return{
      form:{
        sId:ref(''),
        sName:ref(''),
        sSex:ref(''),
        sTel:ref(''),
        sAccept:ref(''),
        sDay:ref(''),
        sTestnum:ref(''),

      },
      form1:{
        gGrade1:ref(''),
        gGrade2:ref(''),
        gGrade3:ref(''),
        gGrade4:ref(''),
      }
    }

  },
  methods:{
    goOut(){
      this.$router.push('/login/loginHome')
    },
    enroll(){
      let data={
        sId:this.form.sId,
        enType:this.form.sAccept
      }
      request.post("/api/enroll/insert",data).then(res=>{
        if(res.success===false)
        {
          ElMessage.error("学时不够")
        }else{
          ElMessage.success("成功")
        }
      })
    },
    getData(){
      let data=JSON.parse(localStorage.getItem("data"))
      request.post("/api/student/getByuserId?userId="+data.userId).then(res=>{
        if(res.data!=null){
          this.form=res.data
        }

      })
      request.post("/api/student/getByuserId?userId="+data.userId).then(res=>{//通过用户id查找的学生id
        //改这里的接口就行了
        if(res.data!=null){
          request.post("/api/grade/getGradeBySId?sid="+res.data.sId).then(res=>{
            if(res.data!=null){
              this.form1=res.data
            }

          })
        }

      })

      //获取学生成绩
    }
  },
  created() {
    this.getData()
  }
}
</script>

<style scoped>
.el-descriptions {
  margin-top: 20px;
}
</style>